<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="企业名称" prop="name">
      <el-input v-model="dataForm.name" placeholder="企业名称"></el-input>
    </el-form-item>
    <el-form-item label="企业地址" prop="address">
      <el-input v-model="dataForm.address" placeholder="企业地址"></el-input>
    </el-form-item>
    <el-form-item label="企业电话" prop="phone">
      <el-input v-model="dataForm.phone" placeholder="企业电话"></el-input>
    </el-form-item>
    <el-form-item label="企业邮箱" prop="email">
      <el-input v-model="dataForm.email" placeholder="企业邮箱"></el-input>
    </el-form-item>
    <el-form-item label="联系人" prop="linkman">
      <el-input v-model="dataForm.linkman" placeholder="联系人"></el-input>
    </el-form-item>
    <el-form-item label="联系人电话" prop="linkphone">
      <el-input v-model="dataForm.linkphone" placeholder="联系人电话"></el-input>
    </el-form-item>
      <el-form-item label="邮政编码" prop="zipcode">
        <el-input v-model="dataForm.zipcode" placeholder="邮政编码"></el-input>
      </el-form-item>
      <el-form-item label="实际生产地址" prop="actualProductionAddress">
        <el-input v-model="dataForm.actualProductionAddress" placeholder="实际生产地址"></el-input>
      </el-form-item>
    <el-form-item label="技术人员" prop="technicist">
      <el-input v-model="dataForm.technicist" placeholder="技术人员"></el-input>
    </el-form-item>
    <el-form-item label="技术员电话" prop="technicistPhone">
      <el-input v-model="dataForm.technicistPhone" placeholder="技术员电话"></el-input>
    </el-form-item>
    <el-form-item label="营业执照" prop="businessLicense">
      <el-input v-model="dataForm.businessLicense" placeholder="营业执照"></el-input>
    </el-form-item>
    <el-form-item label="注册日期" prop="registerData">
      <el-input v-model="dataForm.registerData" placeholder="注册日期"></el-input>
    </el-form-item>
    <el-form-item label="状态" prop="status">
      <el-input v-model="dataForm.status" placeholder="状态"></el-input>
    </el-form-item>
    <el-form-item label="创建时间" prop="createTime">
      <el-input v-model="dataForm.createTime" placeholder="创建时间"></el-input>
    </el-form-item>
    <el-form-item label="更新时间" prop="updateTime">
      <el-input v-model="dataForm.updateTime" placeholder="更新时间"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: null,
          name: '',
          address: '',
          phone: '',
          email: '',
          linkman: '',
          linkphone: '',
          zipcode: '',
          actualProductionAddress: '',
          technicist: '',
          technicistPhone: '',
          businessLicense: '',
          registerData: '',
          status: '',
          createTime: '',
          updateTime: ''
        },
        dataRule: {
          name: [
            { required: true, message: '企业名称不能为空', trigger: 'blur' }
          ],
          address: [
            { required: true, message: '企业地址不能为空', trigger: 'blur' }
          ],
          phone: [
            { required: true, message: '企业电话不能为空', trigger: 'blur' }
          ],
          email: [
            { required: true, message: '企业邮箱不能为空', trigger: 'blur' }
          ],
          linkman: [
            { required: true, message: '联系人不能为空', trigger: 'blur' }
          ],
          linkphone: [
            { required: true, message: '联系人电话不能为空', trigger: 'blur' }
          ],
          technicist: [
            { required: true, message: '技术人员不能为空', trigger: 'blur' }
          ],
          technicistPhone: [
            { required: true, message: '技术员电话不能为空', trigger: 'blur' }
          ],
          businessLicense: [
            { required: true, message: '营业执照不能为空', trigger: 'blur' }
          ],
          registerData: [
            { required: true, message: '注册日期不能为空', trigger: 'blur' }
          ],
          status: [
            { required: true, message: '状态不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          updateTime: [
            { required: true, message: '更新时间不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/reportapproval/entrepreneur/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then((data) => {
              if (data && data.code === 0) {
                this.dataForm = data.entrepreneur;
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/reportapproval/entrepreneur/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData(this.dataForm)
            }).then((data) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
